<script>
import InfoList from '@/views/mall/managementend/ordergoods/sidebar-order/infoList.vue'
import { orderDetail } from '@/api/mallApi/order'

export default {
  name: 'InfoPage',
  components: { InfoList },
  data() {
    return {
      activeName: '1',
      // 表格数据
      tableData: [],
      // 加载状态
      loading: false,
      // 订单编号
      orderCode: '',
      // 工厂
      factory: '',
      // 服务中心
      serviceCenter: '',
      pageNum: 1,
      pageSize: 10,
      total: 0
    }
  },
  created() {
    this.getTableData()
  },
  methods: {
    handleList(tab) {
      this.activeName = tab.name
      this.getTableData()
    },
    // 获取表格数据
    getTableData() {
      this.loading = true
      const params = {
        pageNo: this.pageNum,
        pageSize: this.pageSize,
        status: parseInt(this.activeName),
        orderCode: this.orderCode
      }
      orderDetail(params)
        .then((res) => {
          if (res.code === '00000') {
            this.tableData = res.data.rows
            this.total = res.data.totalRows
          }
          this.loading = false
        })
        .catch((error) => {
          this.loading = false
        })
    },
    // 分页
    handleCurrentChange(val) {
      this.pageNum = val
      this.getTableData()
    },
    changeSize(val) {
      this.pageSize = val
      this.getTableData()
    },
    // 搜索
    handleSearch() {
      this.getTableData()
    },
    reLoad() {
      this.getTableData()
    }
  }
}
</script>

<template>
  <div class="InfoPage">
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleList">
      <div class="top">
        <div class="topLeft">
          <div>
            <p>订单号:</p>
            <el-input
              v-model="orderCode"
              placeholder="请填写订单编号"
              style="width: 200px; margin-left: 20px"
              clearable
            ></el-input>
          </div>
          <div>
            <p>工厂:</p>
            <el-select
              v-model="factory"
              placeholder="请选择工厂"
              clearable
              style="width: 200px; margin-left: 20px"
            >
              <el-option label="工厂1" value="工厂1"></el-option>
              <el-option label="工厂2" value="工厂2"></el-option>
              <el-option label="工厂3" value="工厂3"></el-option>
            </el-select>
          </div>
          <div>
            <p>服务中心:</p>
            <el-select
              v-model="serviceCenter"
              placeholder="请选择服务中心"
              clearable
              style="width: 200px; margin-left: 20px"
            >
              <el-option label="服务中心1" value="服务中心1"></el-option>
              <el-option label="服务中心2" value="服务中心2"></el-option>
              <el-option label="服务中心3" value="服务中心3"></el-option>
            </el-select>
          </div>
        </div>
        <div class="topRight">
          <el-button
            :style="{ marginLeft: '20px' }"
            type="primary"
            @click="handleSearch"
          >
            查询
          </el-button>
          <el-button :style="{ marginLeft: '20px' }" @click="handleSearch">
            重置
          </el-button>
        </div>
      </div>
      <div class="separation"></div>
      <div class="exportBtn">
        <div class="exportBtnLeft"></div>
        <div class="exportBtnRight">
          <el-button :style="{ marginLeft: '20px' }"> 导出 </el-button>
        </div>
      </div>
      <el-tab-pane label="待处理" name="1">
        <InfoList
          :activeName="activeName"
          :tableData="tableData"
          :loading="loading"
          @reLoad="reLoad"
          @handleSearch="handleSearch"
        ></InfoList>
      </el-tab-pane>
      <el-tab-pane label="已处理" name="2">
        <InfoList
          :activeName="activeName"
          :tableData="tableData"
          :loading="loading"
          @reLoad="reLoad"
          @handleSearch="handleSearch"
        ></InfoList>
      </el-tab-pane>
      <el-tab-pane label="已驳回" name="4">
        <InfoList
          :activeName="activeName"
          :tableData="tableData"
          :loading="loading"
          @handleSearch="handleSearch"
        ></InfoList>
      </el-tab-pane>
      <el-tab-pane label="已打款" name="3">
        <InfoList
          :activeName="activeName"
          :tableData="tableData"
          :loading="loading"
          @handleSearch="handleSearch"
        ></InfoList>
      </el-tab-pane>
    </el-tabs>
    <el-row
      type="flex"
      justify="end"
      style="margin-top: 20px; margin-right: 20px"
    >
      <el-pagination
        background
        @current-change="handleCurrentChange"
        @size-change="changeSize"
        :current-page="pageNum"
        :page-size="pageSize"
        :page-sizes="[10, 20, 30, 40]"
        layout="total, prev, pager, next, jumper, sizes"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </div>
</template>

<style scoped lang="scss">
.InfoPage {
  width: 98%;
  min-height: 750px;
  margin-top: 1%;
  margin-bottom: 1%;
  margin-left: 1%;
  background-color: #fff;
  overflow: hidden;
  .top {
    width: 100%;
    min-height: 45px;
    display: flex;
    justify-content: space-between;
    .topLeft {
      width: 1050px;
      display: flex;
      margin-top: -10px;
      > div {
        display: flex;
        align-items: center;
        margin-left: 10px;
        p {
          font-size: 14px;
        }
      }
    }
    .topRight {
    }
  }
  .separation {
    width: 104%;
    margin-left: -2%;
    background: #efefef;
  }
  .exportBtn {
    width: 100%;
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    .exportBtnLeft {
      width: 70%;
    }
    .exportBtnRight {
    }
  }
}
</style>
